package com.lt73.dynamicdatasource.controller;

import com.lt73.dynamicdatasource.entity.Article;
import com.lt73.dynamicdatasource.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 数据填充例子
 *
 * @Author: hanxiao
 * @Date: 2022/4/15 11:43
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping("/insert")
    public Boolean insert() {

        //注册用户
        Article article = new Article();
        article.setContent("aaaa");
        article.setTitle(LocalDateTime.now().toString());
        article.setStatus(1);

        return articleService.insert(article);
    }

    @PutMapping("/update")
    public Boolean update() {

        //注册用户
        Article article = new Article();
        article.setId("1514814593479737346");
        article.setContent("bbbb");

        return articleService.update(article);
    }

    @GetMapping("/list")
    public List<Article> list() {
        return articleService.list();
    }

}
